<?php
/**
 * 权限管理
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-6-17
 * Time: 下午2:37
 */
namespace app\modules\content\controllers;

use app\libs\Pager;
use app\modules\content\models\IeltsVersion;
use yii;
use app\libs\ApiControl;
use app\modules\content\models\IeltsSpeak;
use app\modules\content\models\IeltsSpeakList;
use app\libs\GetData;

class VersionController extends ApiControl
{
    public $enableCsrfValidation = false;


    /**
     * [actionAdd description]
     * @Author don
     * @Date   2022-03-07
     * @return [type]     [description]
     */
    public function actionIndex()
    {
        if (!$_POST) {
            $data = Yii::$app->db->createCommand("select * from {{%ielts_version}} order by id desc")->queryOne();
            return $this->render('add', ['data' => $data]);
        } else {
            $IeltsSpeak = new IeltsVersion();
            $getdata = new GetData();
            $must = array('num' => '版本号', 'file' => '文件地址');
            $data = $getdata->PostData($must, 'ielts_version');
            if (empty($data['id'])) {
                $re = Yii::$app->db->createCommand()->insert("{{%ielts_version}}", $data)->execute();
            } else {
                $re = $IeltsSpeak->updateAll($data, 'id=:id', array(':id' => $data['id']));
            }
            if ($re) {
                $this->redirect('index');
            } else {
                echo '<script>alert("数据修改/添加失败，请重试");history.go(-1);</script>';
                die;
            }
        }

    }

}